package cn.funnyxb.tools.appFrame;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.widget.Toast;
import cn.funnyxb.powerremember.ad.ADController;
import cn.funnyxb.powerremember.db.AllTableHolders;
import cn.funnyxb.powerremember.pullMsg.beans.AppConfig;
import cn.funnyxb.powerremember.pullMsg.beans.AppConfig.Watcher;
import cn.funnyxb.powerremember.service.AppService;
import cn.funnyxb.powerremember.tts.TTSHolder;
import cn.funnyxb.tools.appFrame.activityFrame.ActivitysHolder;
import cn.funnyxb.tools.appFrame.dataStructure.MessageCache;
import cn.funnyxb.tools.appFrame.database.DBHolder;
import cn.funnyxb.tools.appFrame.debugTool.Debuger;
import cn.funnyxb.tools.appFrame.util.FileTool;
import java.io.File;
import java.io.IOException;

public class App extends Application
{
  private static App app = null;
  private ActivitysHolder activitysHolder = null;
  private ADController adController;
  private AllTableHolders allTableHolders;
  private AppConfig appConfig = null;
  private AppService appService;
  private DBHolder dbHolder = null;
  private Typeface myTypeface = null;
  private ServiceConnection sc = new 1(???);
  private TTSHolder ttsHolder = null;

  public static App getApp()
  {
    return app;
  }

  private void log(String paramString)
  {
    Debuger.log("app", paramString);
  }

  private void prepareDbAndTbHolder()
    throws Exception
  {
    this.dbHolder = new DBHolder(this, "powerremember.db", AppDBConfig.DBVERSION, null);
    this.allTableHolders = AllTableHolders.initOnce_AllTableHolders(this.dbHolder);
    log("prepareDB dbholder=" + this.dbHolder);
  }

  private void startAppService()
  {
    log("startAppService");
    Intent localIntent = new Intent(this, AppService.class);
    startService(localIntent);
    bindService(localIntent, this.sc, 1);
  }

  private void stopAppService()
  {
    try
    {
      unbindService(this.sc);
      stopService(new Intent(this, AppService.class));
      return;
    }
    catch (Exception localException)
    {
    }
  }

  public void destroy()
  {
    log("call destroy");
    if (this.dbHolder != null)
      this.dbHolder.closeDB();
    stopAppService();
    this.ttsHolder.shutdown();
    this.appConfig = null;
    this.adController = null;
  }

  public ADController getADController()
  {
    log("getAdController=" + this.adController);
    if (this.adController == null)
      this.adController = new ADController(this);
    return this.adController;
  }

  public ActivitysHolder getActivitysHolder()
  {
    return this.activitysHolder;
  }

  public AllTableHolders getAllTableHolders()
  {
    return this.allTableHolders;
  }

  public AppConfig getAppConfig()
  {
    if (this.appConfig == null)
      this.appConfig = AppConfig.getAppConfigFromCache(this);
    return this.appConfig;
  }

  public AppService getAppService()
  {
    return this.appService;
  }

  public DBHolder getDBHolder()
  {
    if (this.dbHolder == null)
      log("reget DBHolder");
    try
    {
      this.dbHolder = new DBHolder(this, "powerremember.db", AppDBConfig.DBVERSION, null);
      return this.dbHolder;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      Toast.makeText(this, "数据读取异常", 1).show();
    }
  }

  public Typeface getMyTypeface()
  {
    return this.myTypeface;
  }

  public TTSHolder getTTSHolder()
  {
    if (this.ttsHolder == null)
      this.ttsHolder = new TTSHolder(this);
    return this.ttsHolder;
  }

  public void initTTSHolder()
  {
    this.ttsHolder = new TTSHolder(this);
  }

  public void onConfigurationChanged(Configuration paramConfiguration)
  {
    super.onConfigurationChanged(paramConfiguration);
  }

  public void onCreate()
  {
    super.onCreate();
    log("onCreate" + this);
    app = this;
    this.activitysHolder = ActivitysHolder.getInstance();
  }

  public boolean prepareDB(MessageCache<String> paramMessageCache)
  {
    paramMessageCache.putMsg(getString(2131034114));
    int j;
    if (getDatabasePath("powerremember.db").exists())
      j = 1;
    while (true)
    {
      label25: return j;
      paramMessageCache.putMsg(getString(2131034115));
      switch (AppDBConfig.dbType)
      {
      default:
        j = 0;
        break;
      case 10:
        paramMessageCache.putMsg(getString(2131034116));
      case 20:
        while (true)
        {
          try
          {
            FileTool.copyFileFromAssets(this, "powerremember.db", getDatabasePath("text").getParentFile().getAbsolutePath() + "/", "powerremember.db");
            label131: j = 1;
          }
          catch (IOException localIOException3)
          {
            j = 0;
          }
          break label25:
          paramMessageCache.putMsg(getString(2131034116));
          try
          {
            FileTool.copyFileFromAssets(this, "powerremember.db" + AppDBConfig.DBFILENAME_ZIPEXTNAME, getDatabasePath("text").getParentFile().getAbsolutePath() + "/", null);
            paramMessageCache.putMsg(getString(2131034117));
            FileTool.Ectract(getDatabasePath("powerremember.db") + AppDBConfig.DBFILENAME_ZIPEXTNAME, getDatabasePath("text").getParentFile().getAbsolutePath() + "/");
            paramMessageCache.putMsg(getString(2131034118));
            new File(getDatabasePath("powerremember.db") + AppDBConfig.DBFILENAME_ZIPEXTNAME).delete();
          }
          catch (IOException localIOException2)
          {
            j = 0;
          }
        }
      case 30:
      }
    }
    paramMessageCache.putMsg(getString(2131034116));
    int i = 1;
    if (i > AppDBConfig.splitFileCountOfDB)
    {
      label349: paramMessageCache.putMsg(getString(2131034119));
      FileTool.reorganization(getDatabasePath("powerremember.db") + AppDBConfig.DBFILENAME_ZIPEXTNAME, AppDBConfig.splitFileCountOfDB);
      paramMessageCache.putMsg(getString(2131034118));
    }
    for (int k = 1; ; ++k)
    {
      while (true)
      {
        if (k <= AppDBConfig.splitFileCountOfDB)
          break label684;
        paramMessageCache.putMsg(getString(2131034117));
        FileTool.Ectract(getDatabasePath("powerremember.db") + ".zip", getDatabasePath("text").getParentFile().getAbsolutePath() + "/");
        paramMessageCache.putMsg(getString(2131034118));
        new File(getDatabasePath("powerremember.db") + AppDBConfig.DBFILENAME_ZIPEXTNAME).delete();
        break label131:
        try
        {
          log("copy ing: powerremember.db" + AppDBConfig.DBFILENAME_ZIPEXTNAME + "_" + i + "  --  " + getDatabasePath("text").getParentFile().getAbsolutePath());
          boolean bool = FileTool.copyFileFromAssets(this, "powerremember.db" + AppDBConfig.DBFILENAME_ZIPEXTNAME + "_" + i, getDatabasePath("text").getParentFile().getAbsolutePath() + "/", null);
          if (bool)
            break label678;
          j = 0;
        }
        catch (IOException localIOException1)
        {
          j = 0;
        }
      }
      break label25:
      label678: ++i;
      break label349:
      label684: log("del=" + getDatabasePath("powerremember.db") + AppDBConfig.DBFILENAME_ZIPEXTNAME + "_" + k);
      new File(getDatabasePath("powerremember.db") + AppDBConfig.DBFILENAME_ZIPEXTNAME + "_" + k).delete();
    }
  }

  // ERROR //
  public Exception prepareStartWhenLogo(MessageCache<String> paramMessageCache)
  {
    // Byte code:
    //   0: aload_1
    //   1: invokevirtual 302	cn/funnyxb/tools/appFrame/dataStructure/MessageCache:clearCaches	()V
    //   4: aload_1
    //   5: ldc_w 304
    //   8: invokevirtual 220	cn/funnyxb/tools/appFrame/dataStructure/MessageCache:putMsg	(Ljava/lang/Object;)V
    //   11: aload_0
    //   12: ldc_w 304
    //   15: invokespecial 54	cn/funnyxb/tools/appFrame/App:log	(Ljava/lang/String;)V
    //   18: ldc2_w 305
    //   21: invokestatic 312	java/lang/Thread:sleep	(J)V
    //   24: aload_1
    //   25: ldc_w 314
    //   28: invokevirtual 220	cn/funnyxb/tools/appFrame/dataStructure/MessageCache:putMsg	(Ljava/lang/Object;)V
    //   31: aload_0
    //   32: aload_1
    //   33: invokevirtual 316	cn/funnyxb/tools/appFrame/App:prepareDB	(Lcn/funnyxb/tools/appFrame/dataStructure/MessageCache;)Z
    //   36: ifne +26 -> 62
    //   39: aload_1
    //   40: aload_0
    //   41: ldc_w 317
    //   44: invokevirtual 214	cn/funnyxb/tools/appFrame/App:getString	(I)Ljava/lang/String;
    //   47: invokevirtual 220	cn/funnyxb/tools/appFrame/dataStructure/MessageCache:putMsg	(Ljava/lang/Object;)V
    //   50: new 319	cn/funnyxb/tools/appFrame/exceptions/DBPrepareException
    //   53: dup
    //   54: invokespecial 320	cn/funnyxb/tools/appFrame/exceptions/DBPrepareException:<init>	()V
    //   57: astore 4
    //   59: aload 4
    //   61: areturn
    //   62: aload_0
    //   63: invokespecial 322	cn/funnyxb/tools/appFrame/App:startAppService	()V
    //   66: aload_0
    //   67: invokespecial 324	cn/funnyxb/tools/appFrame/App:prepareDbAndTbHolder	()V
    //   70: aload_1
    //   71: ldc_w 326
    //   74: invokevirtual 220	cn/funnyxb/tools/appFrame/dataStructure/MessageCache:putMsg	(Ljava/lang/Object;)V
    //   77: aload_0
    //   78: invokevirtual 329	cn/funnyxb/tools/appFrame/App:prepareTypeface	()V
    //   81: ldc2_w 305
    //   84: invokestatic 312	java/lang/Thread:sleep	(J)V
    //   87: aconst_null
    //   88: astore 4
    //   90: goto -31 -> 59
    //   93: astore_3
    //   94: aload_3
    //   95: invokevirtual 175	Exception:printStackTrace	()V
    //   98: aload_0
    //   99: ldc_w 331
    //   102: invokespecial 54	cn/funnyxb/tools/appFrame/App:log	(Ljava/lang/String;)V
    //   105: aload_3
    //   106: astore 4
    //   108: goto -49 -> 59
    //   111: astore_2
    //   112: goto -88 -> 24
    //   115: astore 5
    //   117: goto -30 -> 87
    //
    // Exception table:
    //   from	to	target	type
    //   66	70	93	Exception
    //   18	24	111	Exception
    //   81	87	115	Exception
  }

  public void prepareTypeface()
  {
    this.myTypeface = Typeface.createFromAsset(getAssets(), "font/seguibd.ttf");
  }

  public void restartPackage()
  {
    ((ActivityManager)getSystemService("activity")).restartPackage(getPackageName());
  }

  public void setAppConfig(AppConfig paramAppConfig)
  {
    log("new appconfig=" + paramAppConfig);
    this.appConfig = paramAppConfig;
    paramAppConfig.saveAsCache(this);
    AppConfig.Watcher localWatcher = AppConfig.getWatcher();
    log("watcher=" + localWatcher);
    if (localWatcher == null)
      return;
    localWatcher.onConfigChanger(paramAppConfig);
  }
}

/* Location:           E:\Desktop\复件 classes_dex2jar.jar
 * Qualified Name:     cn.funnyxb.tools.appFrame.App
 * JD-Core Version:    0.5.3
 */